package com.dumas.utils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.client.methods.HttpGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Api(tags = "测试接口")
@RestController
@RequestMapping(value = "/111")
public class ApiUtilImp implements ApiUtil{

    @Autowired
    private RestTemplate restTemplate;
    private HttpGet httpGet;

    @ApiOperation(value = "接口内容", notes = "返回接口内的数据")
    @GetMapping
    @Override
    public String apiGet(String str) {
        String apiURL = "https://autumnfish.cn/"+str;

        ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiURL, String.class);

        if (200 == responseEntity.getStatusCodeValue()) {
             return responseEntity.getBody();
        } else {
            return "error with code : " + responseEntity.getStatusCodeValue();
        }
    }
}
